<%@ page language="java" pageEncoding="utf-8" contentType="text/html;charset=utf-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<%@ include file="../../../common/common.jsp" %>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<title>添加/编辑广告 - ${title }</title>
	<link rel="stylesheet" href="${pageContext.request.contextPath}/static/js/uploadify/uploadify.css">

</head>
<body <%@ include file="../../../common/skin.jsp" %>>
<%@ include file="../../../common/head.jsp" %>
<%@ include file="../../../common/menu.jsp" %>
<div class="J_content">
	<div class="mt20 plr20">
		<div class="J_filter">
			<table class="not_hightlight" style="width: 100%;">
				<tbody>
				<tr>
					<td class="t_right">
						<div class="fr">
							<a href="javascript:myBack()">
								<i class="icon"></i><span>返回上一页</span>
							</a>
						</div>
					</td>
				</tr>
				</tbody>
			</table>
		</div>
		<div class="J_formTable l_form_table mgt40">
			<form action="${ctx}/advSpace/ajax/save" id="editForm" method="post">
				<input type="hidden" name="id" value="${advSpace.id }"/>
				<input type="hidden" name="picUrl" id="picUrl" value="${advSpace.url }"/>
				<table>
					<tr>
						<td class="l_title w200">广告位置：<font color="red">*</font></td>
						<td>
							<div class="t_opacitySelect ml10">
								<select name="dicCode">
									<option value="">请选择</option>
									<c:forEach items="${advDictionaryList }" var="c">
										<option value="${c.code }"
												<c:if test="${c.code == advSpace.dicCode }">selected</c:if>
										>${c.name }</option>
									</c:forEach>
								</select>
							</div>
						</td>
					</tr>
					<tr>
						<td class="l_title w200">标题：</td>
						<td>
							<div class="J_toolsBar fl">
								<div class="t_text w600 ml10">
									<label>
										<input type="text" name="title" value="${advSpace.title }" >
									</label>
								</div>
							</div>
						</td>
					</tr>

					<tr id="contentTr">
						<td class="l_title w200">内容：</td>
						<%--<td>--%>
							<%--<div class="J_toolsBar">--%>
								<%--<label>--%>
									<%--<script type="text/plain" id="content" name="content">${advSpace.content}</script>--%>
								<%--</label>--%>
							<%--</div>--%>
						<%--</td>--%>
						<td>
							<div class="J_toolsBar fl">
								<div class="t_text w600 ml10">
									<label>
										<input type="text" name="content" value="${advSpace.content }" >
									</label>
								</div>
							</div>
						</td>
					</tr>

					<tr>
						<td class="l_title w200">广告链接：</td>
						<td>
							<div class="J_toolsBar fl">
								<div class="t_text w600 ml10">
									<label>
										<input type="text" name="advUrl" value="${advSpace.advUrl }" >
									</label>
								</div>
							</div>
						</td>
					</tr>

					<tr>
						<td class="l_title w200">图片：<a href="${ctx }/cms/article/flashView" target="_blank"><font color="red">无法上传？</font></a></td>
						<td>
							<div class="J_toolsBar fl">
								<div class=" w200 ml10">
									<label>
										<input type="file" id="attachImage" />
									</label>
								</div>
							</div>
						</td>
					</tr>
					<tr>
						<td class="l_title"></td>
						<td>
							<div class="J_toolsBar fl">
								<div class="t_img w100 ml10">
									<c:choose>
										<c:when test="${advSpace.url != null}">
											<img src="${ctx }${advSpace.url}" id="attachURL" width="100px" height="100px" />
										</c:when>
										<c:otherwise>
											<img src="${ctx }/static/images/J_null.png" id="attachURL" width="100px" height="100px" />
										</c:otherwise>
									</c:choose>

								</div>
							</div>
						</td>
					</tr>

					<tr id="orderNoTr">
						<td class="l_title w200">排序：</td>
						<td>
							<div class="J_toolsBar fl">
								<div class="t_text w200 ml10">
									<label>
										<input type="number" name="orderNo" value="${advSpace.orderNo }" >
									</label>
								</div>
							</div>
						</td>
					</tr>

					<tr>
						<td class="l_title w200">应用渠道：<font color="red">*</font></td>
						<td>
							<div class="t_opacitySelect ml10">
								<select name="channel" id="channel">
									<option value="">请选择</option>
									<option value="0"
											<c:if test="${advSpace.channel==0}">selected</c:if>
									>pc 渠道</option>

									<option value="1"
											<c:if test="${advSpace.channel==1}">selected</c:if>
									>h5 渠道</option>

									<option value="2"
											<c:if test="${advSpace.channel==2}"> selected</c:if>
									>pc 和 h5 渠道</option>
								</select>
							</div>
						</td>
					</tr>

					<tr>
						<td colspan="2">
							<div class="J_toolsBar mgt40">
								<div class="t_buttonGroup">
									<a class="abtn red" href="javascript:mySubmit();">
										<i class="icon"></i>保存
									</a>
									<a class="abtn gray" href="javascript:myBack();">
										<i class="icon"></i>返回
									</a>
								</div>
							</div>
						</td>
					</tr>
				</table>

			</form>
		</div>
	</div>
</div>
<script src="${pageContext.request.contextPath}/static/js/uploadify/jquery.uploadify.js"></script>

<script type="text/javascript">
	//表单验证
	$(function(){
		$('#editForm').validator({
			valid : function(form){
				$('#editForm').ajaxSubmit({
					success : function(result){
						if(result.success){
							layer.alert('保存成功');
							window.location.href="${ctx}/advSpace/list"
						}
					}
				});
			}
		});
	});

	function myBack(){
		window.location.href="${ctx}/advSpace/list";
	}

	function mySubmit(){
		$('#editForm').submit();
	}

	$(function(){

		$("#rootColumnId").trigger("change")
		var articleType = '${article.type}';
		if(articleType == 1){
			$('#contentTr').hide();
			$("#orderNoTr").hide();
			$("#hrefTr").show();
		}else if(articleType == 2){
			$('#contentTr').hide();
			$("#orderNoTr").show();
			$("#hrefTr").show();
		}
	});
	$("#attachImage").uploadify(
			{
				'swf' : '${pageContext.request.contextPath}/static/js/uploadify/uploadify.swf',
				'uploader' : '${pageContext.request.contextPath}/upload/uploadAttach',
				'cancelImg' : '${pageContext.request.contextPath}/static/js/uploadify/uploadify-cancel.png',
				'queueID' : 'fileQueue',
				'auto' : true,
				'multi' : false,
				'simUploadLimit' : 1,
				'buttonText' : '上传图片',
				'fileObjName' : 'fileData',
				'width' : 70,
				'height' : 20,
				'uploadLimit':3,
				'onUploadSuccess' : function(file, data, response) {
					if(data != null){
						var attachUrl = '${pageContext.request.contextPath}' + data;
						$("#attachURL").attr('src',attachUrl);
						$("#picUrl").val(data);
					}
				}
			});

	$('input[name="articleType"]').on('click', function(){
		var val = $('input[name="articleType"]:checked').val();
		if(val == 'contentType'){
			$('#contentTr').show();
			$("#hrefTr").hide();
			$("#orderNoTr").hide();
		}else if(val == 'hrefType'){
			$('#contentTr').hide();
			$("#orderNoTr").hide();
			$("#hrefTr").show();
		}else if(val == 'adType'){
			$('#contentTr').hide();
			$("#orderNoTr").show();
			$("#hrefTr").show();
		}
	});
</script>

</body>
</html>